package business.util;

import java.text.DecimalFormat;

import javax.swing.text.DefaultFormatterFactory;
import javax.swing.text.MaskFormatter;
import javax.swing.text.NumberFormatter;

public class Mascaras
{
	public static MaskFormatter CPF() throws Exception
	{
		String mascara = "###.###.###-##";
		MaskFormatter mascaraFormatada = null;
		
		try
		{
			mascaraFormatada = new MaskFormatter(mascara);
		}
		catch(Exception ex)
		{
			throw ex;
		}
		
		return mascaraFormatada;
	}
	
	public static MaskFormatter CNPJ() throws Exception
	{
		String mascara = "##.###.###/####-##";
		MaskFormatter mascaraFormatada = null;
		
		try
		{
			mascaraFormatada = new MaskFormatter(mascara);
		}
		catch(Exception ex)
		{
			throw ex;
		}
		
		return mascaraFormatada;
	}
	
	public static MaskFormatter TELEFONE() throws Exception
	{
		String mascara = "(##)####-####";
		MaskFormatter mascaraFormatada = null;
		
		try
		{
			mascaraFormatada = new MaskFormatter(mascara);
		}
		catch(Exception ex)
		{
			throw ex;
		}
		
		return mascaraFormatada;
	}
	
	public static MaskFormatter CEP() throws Exception
	{
		String mascara = "##.###-###";
		MaskFormatter mascaraFormatada = null;
		
		try
		{
			mascaraFormatada = new MaskFormatter(mascara);
		}
		catch(Exception ex)
		{
			throw ex;
		}
		
		return mascaraFormatada;
	}
	
	public static DefaultFormatterFactory DECIMAL() throws Exception
	{  
		String mascara = "#,###.##";
		DefaultFormatterFactory mascaraFormatada = null;
		DecimalFormat decimal = null;
		NumberFormatter formatarNumero = null;
		
		try
		{
			decimal = new DecimalFormat(mascara);
			formatarNumero = new NumberFormatter(decimal);
			formatarNumero.setAllowsInvalid(false);
			mascaraFormatada = new DefaultFormatterFactory(formatarNumero);
		}
		catch(Exception ex)
		{
			throw ex;
		}
		
		return mascaraFormatada;
	}
	
	public static MaskFormatter Data() throws Exception
	{
		String mascara = "##/##/####";
		MaskFormatter mascaraFormatada = null;
		
		try
		{
			mascaraFormatada = new MaskFormatter(mascara);
		}
		catch(Exception ex)
		{
			throw ex;
		}
		
		return mascaraFormatada;
	}
}
